package scau.mis4.chanyulin.dao;

import scau.mis4.chanyulin.tools.utils.DbUtils;
import scau.mis4.chanyulin.view.Global;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by cyl on 2017/12/11.
 */
public class OtherDao {

    private static final String TABLE = Global.SENSOR_TABLE_NAME;

    /**
     * 获取数据库大小
     * @return
     */
    public static Double getDataSize() {
        String sql = "SELECT truncate(sum(data_length)/1024/1024,2) AS data_size FROM information_schema.tables WHERE TABLE_SCHEMA = '" + TABLE + "';";
        try {
            ResultSet rs = DbUtils.getStatement().executeQuery(sql);
            System.out.println("[sql] " + sql);
            if (rs.next()) {
                Double result = rs.getDouble("data_size");
                return result;
            } else return null;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
